// 创建基础store
import { createStore } from "vuex";

const defaultState = {
  count: 0,
};

export const counterStore = createStore({
  state: defaultState,
  //同步操作,做运算处理
  mutations: {
    increment(state) {
      state.count++;
    },
    decrement(state) {
      state.count--;
    },
  },

  //异步操作，发请求操作
  actions: {
    increment(context) {
      context.commit("increment");
    },
    decrement(context) {
      context.commit("decrement");
    },
  },
});
